package dao

import "time"

type TimeCondition struct {
	ID         int       `gorm:"primary key" json:"id"`               //编号
	LightId    int       `gorm:"type:int;default 0" json:"lightId"`   //照明策略id
	StartTime  string    `gorm:"type:varchar(60)" json:"startTime"`   //开始时间
	EndTime    string    `gorm:"type:varchar(60)" json:"endTime"`     //结束时间
	Luminance  int       `gorm:"type:int " json:"luminance"`          //开灯亮度
	Remark     string    `gorm:"type:varchar(255)" json:"remark"`     //备注
	CreateTime time.Time `gorm:"type:datetime" json:"createTime"`     //新增时间
	CreateUser int64     `gorm:"type:bigint" json:"createUser"`       //新增记录操作用户ID
	UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"`     //修改时间
	UpdateUser int64     `gorm:"type:bigint" json:"updateUser"`       //修改用户
	IsDeleted  int       `gorm:"type:int;default 0" json:"isDeleted"` //是否删除 0=未删除,1=删除
	Sunshine   int       `gorm:"type:int;default 1" json:"sunshine"`  //日出日落 设置 2=开启,1=不开启
}

func (TimeCondition) TableName() string {
	return "strategy_time_condition"
}

func (c *TimeCondition) Get() error {
	return Db.Debug().Model(&c).Where("id = ? and is_deleted = 0", c.ID).Find(&c).Error
}

func (c *TimeCondition) BatchGet(ids []int) ([]TimeCondition, error) {
	var conditions []TimeCondition
	err := Db.Debug().Model(&c).Where("id in ? and is_deleted = 0", ids).Find(&conditions).Error
	return conditions, err
}

func (c *TimeCondition) GetByLightId() ([]TimeCondition, error) {
	var conditions []TimeCondition
	err := Db.Debug().Model(&c).Where("light_id = ? and is_deleted = 0", c.LightId).Find(&conditions).Error
	return conditions, err
}

func (c *TimeCondition) GetAll() ([]TimeCondition, error) {
	var conditions []TimeCondition
	err := Db.Debug().Model(&c).Find(&conditions).Error
	return conditions, err
}

func (c *TimeCondition) Save() error {
	return Db.Debug().Model(&c).Save(&c).Error
}

func (c *TimeCondition) Update() error {
	return Db.Debug().Model(&c).Updates(&c).Error
}
