package mcuorderitem

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	emo "simrs-vx/internal/domain/main-entities/mcu-order"
	ems "simrs-vx/internal/domain/main-entities/mcu-src"
	erc "simrs-vx/internal/domain/references/common"
	"time"
)

type CreateDto struct {
	McuOrder_Id     *uint              `json:"mcuOrder_id"`
	McuSrc_Code     *string            `json:"mcuSrc_code"`
	Result          *string            `json:"result"`
	Status_Code     erc.DataStatusCode `json:"status_code"`
	ExaminationDate *time.Time         `json:"examinationDate"`
}

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

type FilterDto struct {
	McuOrder_Id *uint              `json:"mcu-order-id"`
	McuSrc_Code *string            `json:"mcu-src-code"`
	Result      *string            `json:"result"`
	Status_Code erc.DataStatusCode `json:"status-code"`
}
type ReadDetailDto struct {
	Id uint `json:"id"`
}

type UpdateDto struct {
	Id uint `json:"id"`
	CreateDto
}

type DeleteDto struct {
	Id uint `json:"id"`
}

type SetScheduleDto struct {
	Id              uint       `json:"id"`
	ExaminationDate *time.Time `json:"examinationDate"`
}

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

type ResponseDto struct {
	ecore.Main
	McuOrder_Id     *uint              `json:"mcuOrder_id"`
	McuOrder        *emo.McuOrder      `json:"mcuOrder,omitempty"`
	McuSrc_Code     *string            `json:"mcuSrc_code"`
	McuSrc          *ems.McuSrc        `json:"mcuSrc,omitempty"`
	Result          *string            `json:"result"`
	Status_Code     erc.DataStatusCode `json:"status_code"`
	ExaminationDate *time.Time         `json:"examinationDate"`
}

func (d McuOrderItem) ToResponse() ResponseDto {
	resp := ResponseDto{
		McuOrder_Id:     d.McuOrder_Id,
		McuOrder:        d.McuOrder,
		McuSrc_Code:     d.McuSrc_Code,
		McuSrc:          d.McuSrc,
		Result:          d.Result,
		Status_Code:     d.Status_Code,
		ExaminationDate: d.ExaminationDate,
	}
	resp.Main = d.Main
	return resp
}

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