package common

type JSONMobileProfile struct {
	VIN           string         `json:"vin"`
	DriverRole    string         `json:"role"`
	Consent       bool           `json:"consent,omitempty"`
	BLEKey        string         `json:"ble_key,omitempty"`
	Settings      []CarSetting   `json:"settings"`
	Subscriptions []Subscription `json:"subscriptions"`
}

func (p *JSONMobileProfile) Populate(driver CarToDriver) {
	p.VIN = driver.VIN
	p.DriverRole = driver.DriverRole
	p.BLEKey = driver.BLEKey

	if driver.Settings == nil {
		p.Settings = make([]CarSetting, 0)
	} else {
		p.Settings = driver.Settings
		for i := range p.Settings {
			p.Settings[i].ClearCreatedAt()
		}
	}

	if driver.Subscriptions == nil {
		p.Subscriptions = make([]Subscription, 0)
	} else {
		p.Subscriptions = driver.Subscriptions
		for i := range p.Subscriptions {
			p.Subscriptions[i].ClearDates()
		}
	}

}

type JSONHMIProfile struct {
	DriverID      string         `json:"driver_id"`
	DriverRole    string         `json:"role"`
	User          UserProfile    `json:"user"`
	Settings      []CarSetting   `json:"settings"`
	Subscriptions []Subscription `json:"subscriptions"`
}

func (p *JSONHMIProfile) Populate(user JSONUserProfile, driver CarToDriver) {
	p.User = UserProfile{
		FirstName: user.FirstName,
		LastName:  user.LastName,
		Email:     user.Email,
		Phone:     user.Phone,
	}
	p.DriverID = driver.DriverID
	p.DriverRole = driver.DriverRole

	if driver.Settings == nil {
		p.Settings = make([]CarSetting, 0)
	} else {
		p.Settings = driver.Settings
		for i := range p.Settings {
			p.Settings[i].ClearCreatedAt()
		}
	}

	if driver.Subscriptions == nil {
		p.Subscriptions = make([]Subscription, 0)
	} else {
		p.Subscriptions = driver.Subscriptions
		for i := range p.Subscriptions {
			p.Subscriptions[i].ClearDates()
		}
	}
}

type JSONHMIUpdateProfile struct {
	DriverID   string      `json:"driver_id"`
	DriverRole string      `json:"role"`
	User       UserProfile `json:"user"`
}

type JSONHMIDeleteProfile struct {
	DriverID string `json:"driver_id" validate:"required,max=100"`
}

type JSONUserProfile struct {
	UserName  string `json:"username"`
	FirstName string `json:"firstname"`
	LastName  string `json:"lastname"`
	Email     string `json:"email"`
	Phone     string `json:"phonenumber"`
}
