package entities

import (
	"time"

	"github.com/UpmeshLTD/urus-aio/infrastructure/common"
)

const (
	FulfillmentStepShippingChannel = 1
	FulfillmentStepOrderDetails    = 2
	FulfillmentStepPickupDetails   = 3
)

type Fulfillment struct {
	BaseUuidEntity

	WorkspaceID string

	PaidOrders []PaidOrder

	CourierDeliveryPlanID *int64
	CourierDeliveryPlan   *CourierDeliveryPlan
	CourierID             *int64
	Courier               *Courier

	PickupPointID     *int64
	PickupPoint       *PickupPoint
	PickupTime        *time.Time
	PickupStartTime   *time.Time
	PickupEndTime     *time.Time
	PickupInstruction *string

	Step int `gorm:"default:1"`

	Draft      bool `gorm:"default:true"`
	Deactivate bool `gorm:"default:false"`
}

type GetFulfillmentsParams struct {
	WorkspaceID string
	Deactivate  bool
	common.Pagination
}

// ToMap
//
// Because Pickup time is depend on Courier
// So, the value of this field will be set in another place
func (f *Fulfillment) ToMap() map[string]interface{} {
	res := map[string]interface{}{
		"Step": f.Step,
	}
	if f.CourierDeliveryPlanID != nil {
		res["CourierDeliveryPlanID"] = f.CourierDeliveryPlanID
	}
	if f.CourierID != nil {
		res["CourierID"] = f.CourierID
	}
	if f.PickupPointID != nil {
		res["PickupPointID"] = f.PickupPointID
	}
	return res
}
