package models

import "time"

type Loker struct {
	Id              uint          `json:"id"`
	CategoryLokerId int           `json:"category_id"`
	CategoryLoker   LokerCategory `gorm:"constraint:OnDelete:CASCADE;foreignKey:CategoryLokerId"`
	Code            string        `json:"code"`
	Status          string        `json:"status"`
	CreatedAt       time.Time     `json:"created_at"`
	UpdatedAt       time.Time     `json:"updated_at"`
}

type ResponseLokerWithoutCategory struct {
	Id        uint      `json:"id"`
	Code      string    `json:"code"`
	Price     int       `json:"price"`
	Status    string    `json:"status"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func (Obj *Loker) ToResponse() *ResponseLokerWithoutCategory {
	return &ResponseLokerWithoutCategory{
		Id:        Obj.Id,
		Code:      Obj.Code,
		Price:     Obj.CategoryLoker.Price,
		Status:    Obj.Status,
		CreatedAt: Obj.CreatedAt,
		UpdatedAt: Obj.UpdatedAt,
	}
}

func ToLokerResponses(datass []Loker) []ResponseLokerWithoutCategory {
	var responses []ResponseLokerWithoutCategory
	for _, data := range datass {
		responses = append(responses, *data.ToResponse())
	}
	return responses
}
