package vehicle_hist

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	ev "simrs-vx/internal/domain/main-entities/vehicle"
	ercm "simrs-vx/internal/domain/references/common"
	"time"
)

type CreateDto struct {
	Vehicle   ev.Vehicle
	Crud_Code ercm.CrudCode `json:"crud_code"`
}

type ReadListDto struct {
	FilterDto
	Includes   string `json:"includes"`
	Pagination ecore.Pagination
}

type FilterDto struct {
	Vehicle_Id *uint         `json:"vehicle-id"`
	Crud_Code  ercm.CrudCode `json:"crud_code"`
}

type ReadDetailDto struct {
	Id       uint16 `json:"id"`
	Includes string `json:"includes"`
}

type MetaDto struct {
	PageNumber int `json:"page_number"`
	PageSize   int `json:"page_size"`
	Count      int `json:"count"`
}

type ResponseDto struct {
	ecore.Main
	Vehicle_Id *uint          `json:"vehicle_id"`
	Vehicle    *ev.Vehicle    `json:"vehicle,omitempty" gorm:"foreignKey:Vehicle_Id;references:Id"`
	Date       *time.Time     `json:"date"`
	Data       *string        `json:"data"`
	Crud_Code  *ercm.CrudCode `json:"crud_code"`
}

func (d VehicleHist) ToResponse() ResponseDto {
	resp := ResponseDto{
		Vehicle_Id: d.Vehicle_Id,
		Vehicle:    d.Vehicle,
		Date:       d.Date,
		Data:       d.Data,
		Crud_Code:  d.Crud_Code,
	}
	resp.Main = d.Main
	return resp
}

func ToResponseList(data []VehicleHist) []ResponseDto {
	resp := make([]ResponseDto, len(data))
	for i, u := range data {
		resp[i] = u.ToResponse()
	}
	return resp
}
