package commerce

import "time"

type InstanceResponse struct {
	ID                      int64                 `json:"id"`
	Status                  string                `json:"status"`
	Hostname                *string               `json:"hostname"`
	MainIP                  *string               `json:"main_ip"`
	SSHPort                 *int                  `json:"ssh_port"`
	OSImage                 *string               `json:"os_image"`
	OSName                  *string               `json:"os_name"`
	ExpiresAt               *time.Time            `json:"expires_at"`
	CreatedAt               *time.Time            `json:"created_at"`
	ProductName             string                `json:"product_name"`
	ProductGroupName        *string               `json:"product_group_name"`
	ProductGroupArea        *int                  `json:"product_group_area,omitempty"`
	ProductGroupNode        *int                  `json:"product_group_node,omitempty"`
	ProductGroupNetworkType *string               `json:"product_group_network_type,omitempty"`
	CPU                     *int                  `json:"cpu"`
	Memory                  *int                  `json:"memory"`
	UpstreamID              *int64                `json:"upstream_id"`
	UpstreamPower           *string               `json:"upstream_power"`
	Cycle                   string                `json:"cycle"`
	UnitPrice               int                   `json:"unit_price"`
	NextRenewAmount         int                   `json:"next_renew_amount"`
	AutoRenew               int                   `json:"auto_renew"`
	SystemDiskSize          *int                  `json:"system_disk_size"`
	DataDiskSize            *int                  `json:"data_disk_size"`
	InBW                    *int                  `json:"in_bw"`
	OutBW                   *int                  `json:"out_bw"`
	Internet                int                   `json:"internet"`
	NatACLLimit             *int                  `json:"nat_acl_limit,omitempty"`
	NatWebLimit             *int                  `json:"nat_web_limit,omitempty"`
	IsLocked                int                   `json:"is_locked"`
	SuspendType             *string               `json:"suspend_type"`
	SecurityGroupID         any                   `json:"security_group_id,omitempty"`
	SecurityGroupName       *string               `json:"security_group_name,omitempty"`
	APIType                 string                `json:"api_type,omitempty"`
	ProvisionConfig         []any                 `json:"provision_config,omitempty"`
	ProvisionPlugin         map[string]any        `json:"provision_plugin,omitempty"`
	PluginManageActions     []any                 `json:"plugin_manage_actions,omitempty"`
	PluginLinks             []any                 `json:"plugin_links,omitempty"`
	Upstream                any                   `json:"upstream,omitempty"`
	UpstreamError           *string               `json:"upstream_error,omitempty"`
	UpstreamPayload         any                   `json:"upstream_payload,omitempty"`
	RootPassword            *string               `json:"root_password,omitempty"`
	ProvisionLog            *string               `json:"provision_log,omitempty"`
	PointRewards            []PointRewardResponse `json:"point_rewards,omitempty"`
	Renewal                 RenewPreviewResponse  `json:"renewal"`
}

type PointRewardResponse struct {
	ID          int64      `json:"id"`
	OrderID     int64      `json:"order_id"`
	InstanceID  *int64     `json:"instance_id"`
	SourceType  string     `json:"source_type"`
	Status      string     `json:"status"`
	StatusLabel string     `json:"status_label"`
	AmountCents int        `json:"amount_cents"`
	RewardRate  int        `json:"reward_rate"`
	Points      int        `json:"points"`
	RefNo       *string    `json:"ref_no"`
	Remark      *string    `json:"remark"`
	CreatedAt   time.Time  `json:"created_at"`
	ClaimedAt   *time.Time `json:"claimed_at"`
}

type RenewPreviewResponse struct {
	InstanceID       int64      `json:"instance_id"`
	Cycles           int        `json:"cycles"`
	UnitAmount       int        `json:"unit_amount"`
	TotalAmount      int        `json:"total_amount"`
	Balance          int        `json:"balance"`
	EnoughBalance    bool       `json:"enough_balance"`
	CurrentExpiresAt *time.Time `json:"current_expires_at"`
	NewExpiresAt     *time.Time `json:"new_expires_at"`
}

type RenewInstanceResponse struct {
	OrderID    int64     `json:"order_id"`
	OrderNo    string    `json:"order_no"`
	Amount     int       `json:"amount"`
	Balance    int       `json:"balance"`
	ExpiresAt  time.Time `json:"expires_at"`
	InstanceID int64     `json:"instance_id"`
}

type UpdateAutoRenewResponse struct {
	ID        int64 `json:"id"`
	AutoRenew int   `json:"auto_renew"`
}

type RefundPolicyResponse struct {
	ActionAllowed          bool            `json:"action_allowed"`
	RefundType             string          `json:"refund_type"`
	RefundAmount           int             `json:"refund_amount"`
	PaidAmount             int             `json:"paid_amount"`
	Reason                 string          `json:"reason"`
	FullRefundDays         int             `json:"full_refund_days"`
	WithinFullRefundWindow bool            `json:"within_full_refund_window"`
	LatestRefund           *RefundResponse `json:"latest_refund"`
}

type RefundResponse struct {
	ID                  int64      `json:"id"`
	RefundNo            string     `json:"refund_no"`
	RefundType          string     `json:"refund_type"`
	RefundAmount        int        `json:"refund_amount"`
	Status              string     `json:"status"`
	ResourceStatus      string     `json:"resource_status"`
	ResourceError       *string    `json:"resource_error"`
	ResourceCompletedAt *time.Time `json:"resource_completed_at"`
	Reason              *string    `json:"reason"`
	CreatedAt           time.Time  `json:"created_at"`
}

type RefundInstanceResponse struct {
	Refund         RefundResponse       `json:"refund"`
	RefundPolicy   RefundPolicyResponse `json:"refund_policy"`
	Balance        int                  `json:"balance"`
	InstanceID     int64                `json:"instance_id"`
	InstanceStatus string               `json:"instance_status"`
}

type UpstreamActionLogResponse struct {
	ID              int64      `json:"id"`
	UserID          *int64     `json:"user_id"`
	OrderID         *int64     `json:"order_id"`
	OrderRefundID   *int64     `json:"order_refund_id"`
	InstanceID      *int64     `json:"instance_id"`
	CloudServerID   *int64     `json:"cloud_server_id"`
	UpstreamID      *int64     `json:"upstream_id"`
	ActionType      string     `json:"action_type"`
	ResourceType    string     `json:"resource_type"`
	ResourceID      *string    `json:"resource_id"`
	Source          string     `json:"source"`
	Status          string     `json:"status"`
	UpstreamTaskID  *int64     `json:"upstream_task_id"`
	RequestMethod   *string    `json:"request_method"`
	RequestPath     *string    `json:"request_path"`
	RequestPayload  any        `json:"request_payload"`
	ResponsePayload any        `json:"response_payload"`
	TaskPayload     any        `json:"task_payload"`
	ErrorMessage    *string    `json:"error_message"`
	Remark          *string    `json:"remark"`
	AttemptCount    int        `json:"attempt_count"`
	LastCheckedAt   *time.Time `json:"last_checked_at"`
	CompletedAt     *time.Time `json:"completed_at"`
	CreatedAt       time.Time  `json:"created_at"`
	UpdatedAt       time.Time  `json:"updated_at"`
}

type InstanceActionResponse struct {
	Action UpstreamActionLogResponse `json:"action"`
	TaskID *int64                    `json:"taskid,omitempty"`
	Result any                       `json:"result,omitempty"`
}
