package transform

import (
	"github.com/UpmeshLTD/urus-aio/infrastructure/db/entities"
	"github.com/UpmeshLTD/urus-aio/shipment/server/http/dto"
)

func GetCourierRequestDTOToEntity(req *dto.GetCourierRequest) *entities.GetCourierParams {
	return &entities.GetCourierParams{
		CourierID: req.CourierID,
	}
}

func GetCouriersRequestDTOToEntity(req *dto.GetCouriersRequest) *entities.GetCouriersParams {
	return &entities.GetCouriersParams{
		Deactivate: req.Deactivate,
		CountryID:  entities.CountryIdsMap[req.CountryCode],
	}
}

func GetCourierResponseEntityToDTO(res *entities.Courier) *dto.GetCourierResponse {
	return &dto.GetCourierResponse{
		ID:         res.ID.ToInt64(),
		Name:       res.Name,
		CountryID:  res.CountryID,
		Deactivate: res.Deactivate,
		Type:       res.Type,
		Code:       res.Code,
	}
}

func GetCouriersResponseEntityToDTO(res []*entities.Courier) *dto.GetCouriersResponse {
	data := make([]*dto.Courier, 0, len(res))
	for _, v := range res {
		data = append(data, &dto.Courier{
			ID:         v.ID.ToInt64(),
			Name:       v.Name,
			CountryID:  v.CountryID,
			Deactivate: v.Deactivate,
			Type:       v.Type,
			Code:       v.Code,
		})
	}

	return &dto.GetCouriersResponse{
		Data: data,
	}
}

func CreateCourierRequestDTOToEntity(req *dto.CreateCourierRequest) *entities.Courier {
	return &entities.Courier{
		Name:       req.Name,
		Deactivate: req.Deactivate,
		CountryID:  req.CountryID,
		Type:       req.Type,
		Code:       req.Code,
	}
}

func CourierEntityToDTO(res *entities.Courier) *dto.Courier {
	return &dto.Courier{
		ID:         res.ID.ToInt64(),
		Name:       res.Name,
		CountryID:  res.CountryID,
		Deactivate: res.Deactivate,
		Type:       res.Type,
		Code:       res.Code,
	}
}

func UpdateCourierRequestDTOToEntity(req *dto.UpdateCourierRequest) *entities.Courier {
	return &entities.Courier{
		Name:       req.Name,
		Deactivate: req.Deactivate,
		CountryID:  req.CountryID,
		Type:       req.Type,
		Code:       req.Code,
	}
}
