package rehab

import (
	erc "simrs-vx/internal/domain/references/common"
	ere "simrs-vx/internal/domain/references/encounter"

	ecore "simrs-vx/internal/domain/base-entities/core"
	"time"
)

type CreateDto struct {
	Encounter_Id        *uint              `json:"encounter_id"`
	Parent_Encounter_Id *uint              `json:"parent_encounter_id"`
	AllocatedVisitCount *int               `json:"allocatedVisitCount"`
	ExpiredAt           *time.Time         `json:"expiredAt"`
	VisitMode_Code      ere.VisitModeCode  `json:"visitMode_code"`
	Status_Code         erc.DataStatusCode `json:"status_code"`
}

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

type FilterDto struct {
	Encounter_Id        *uint             `json:"encounter-id"`
	Parent_Encounter_Id *uint             `json:"parent-encounter-id"`
	VisitMode_Code      ere.VisitModeCode `json:"visitMode-code"`
}

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

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

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

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

type ResponseDto struct {
	ecore.Main
	Encounter_Id        *uint               `json:"encounter_id"`
	Parent_Encounter_Id *uint               `json:"parent_encounter_id"`
	AllocatedVisitCount *int                `json:"allocatedVisitCount"`
	ExpiredAt           *time.Time          `json:"expiredAt"`
	VisitMode_Code      *ere.VisitModeCode  `json:"visitMode_code"`
	Status_Code         *erc.DataStatusCode `json:"status_code"`
}

func (d Rehab) ToResponse() ResponseDto {
	resp := ResponseDto{
		Encounter_Id:        d.Encounter_Id,
		Parent_Encounter_Id: d.Parent_Encounter_Id,
		AllocatedVisitCount: d.AllocatedVisitCount,
		ExpiredAt:           d.ExpiredAt,
		VisitMode_Code:      d.VisitMode_Code,
		Status_Code:         d.Status_Code,
	}
	resp.Main = d.Main
	return resp
}

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