//go:generate ${GOBIN}/dummygen -d=api_dummy.go -package=incident ${GO_MODULE}/pkg/service/incident IncidentService
//go:generate ${GOBIN}/mockgen -destination incident_service_mock.go -package=incident ${GO_MODULE}/pkg/service/incident IncidentService
package incident

import (
	"context"
	"time"

	"github.com/tidbcloud/devops/entity"
)

// params

type CreateIncidentParams struct {
}

type ListIncidentsParam struct {
	Page              int
	PerPage           int
	WarRoomID         *uint64
	StatusIs          *entity.IncidentStatus
	TierIs            *entity.IncidentTier
	ComponentsContain []string
	BizRegionsContain []string
}

func (p ListIncidentsParam) Normalize() ListIncidentsParam {
	if p.Page == 0 {
		p.Page = 1
	}
	if p.PerPage == 0 {
		p.PerPage = 50
	}
	return p
}

type CreateIncidentPostMortemActionParams struct {
	IncidentId               uint64     `json:"incident_id"`
	PostMortemId             *uint64    `json:"postmortem_id"`
	Persons                  []string   `json:"persons"`
	Deadline                 *time.Time `json:"deadline"`
	Title                    string     `json:"title"`
	Type                     *string    `json:"type"`
	Priority                 *string    `json:"priority"`
	Description              string     `json:"description"`
	LinkedJiraIssue          *string    `json:"linked_jira_issue"`
	Status                   *string    `json:"status"`
	CreateAssociatedLarkTask bool       `json:"create_associate_lark_task" binding:"required"`
}

const ActionStatusDefaultVal string = ToDoActionStatusOpen

const (
	ToDoActionStatusOpen       string = "open"
	ToDoActionStatusInProgress string = "in_progress"
	ToDoActionStatusDone       string = "done"
	ToDoActionStatusNoNeed     string = "noneed"
	ToDoActionStatusCanceled   string = "canceled"
)

type CreateIncidentLogItemParams struct {
}

type EditIncidentParams struct {
}

type EditIncidentLogItemParams struct {
}

type EditIncidentPostMortemParams struct {
}

type EditIncidentPostMortemToDoActionParams struct {
	Persons         []string   `json:"persons"`
	Deadline        *time.Time `json:"deadline"`
	Title           *string    `json:"title"`
	Type            *string    `json:"type"`
	Priority        *string    `json:"priority"`
	Description     *string    `json:"description"`
	LinkedJiraIssue *string    `json:"linked_jira_issue"`
	Status          *string    `json:"status"`
}

// apis
type IncidentService interface {
	ListIncidents(ctx context.Context, param ListIncidentsParam) ([]*entity.Incident, int64, error)
	GetIncident(ctx context.Context, id uint64) (*entity.Incident, error)
	CreateIncident(ctx context.Context, incidentCreation *entity.Incident) (uint64, error)
	UpdateIncident(ctx context.Context, incidentId uint64, incidentUpdate *entity.Incident) error
	UpdatePostMortemToDoActionImportStatus(ctx context.Context, incidentId uint64, status string) error
	DeleteIncident(ctx context.Context, id uint64) error
	GenerateReportInFeishuChannel(ctx context.Context, id uint64) error
	ListIncidentLogs(ctx context.Context, incidentId uint64) ([]*entity.IncidentLogItem, error)
	GetIncidentLogItem(ctx context.Context, logItemId uint64) (*entity.IncidentLogItem, error)
	CreateIncidentLogItem(ctx context.Context, incidentId uint64, logCreation *entity.IncidentLogItem) (uint64, error)
	UpdateIncidentLogItem(ctx context.Context, logItemId uint64, logUpdate *entity.IncidentLogItem) error
	DeleteIncidentLogItem(ctx context.Context, id uint64) error

	ListIncidentPostMortemItems(ctx context.Context, incidentId uint64) ([]*entity.IncidentPostMortem, error)
	GetIncidentPostMortem(ctx context.Context, id uint64) (*entity.IncidentPostMortem, error)
	CreateIncidentPostMortem(ctx context.Context, postMortemCreation *entity.IncidentPostMortem) (*entity.IncidentPostMortem, error)
	UpdateIncidentPostMortem(ctx context.Context, id uint64, postMortemUpdate *entity.IncidentPostMortem) error
	DeleteIncidentPostMortem(ctx context.Context, id uint64) error

	ListIncidentPostMortemTimelines(ctx context.Context, postMortemId uint64) ([]*entity.IncidentPostMortemTimelineItem, error)
	GetIncidentPostMortemTimelineItem(ctx context.Context, id uint64) (*entity.IncidentPostMortemTimelineItem, error)
	CreateIncidentPostMortemTimelineItem(ctx context.Context, timelineItemCreation *entity.IncidentPostMortemTimelineItem) (*entity.IncidentPostMortemTimelineItem, error)
	UpdateIncidentPostMortemTimelineItem(ctx context.Context, id uint64, timelineUpdate *entity.IncidentPostMortemTimelineItem) error
	DeleteIncidentPostMortemTimelineItem(ctx context.Context, id uint64) error

	ListIncidentPostMortemToDoActions(ctx context.Context, incidentId uint64, postMortemId *uint64) ([]*entity.IncidentPostMortemToDoAction, error)
	GetIncidentPostMortemToDoActionItem(ctx context.Context, incidentId uint64, postMortemId *uint64, id uint64) (*entity.IncidentPostMortemToDoAction, error)
	CreateIncidentPostMortemToDoActionItem(ctx context.Context, actionCreation *CreateIncidentPostMortemActionParams) (*entity.IncidentPostMortemToDoAction, error)
	UpdateIncidentPostMortemToDoActionItem(ctx context.Context, incidentId uint64, postMortemId *uint64, id uint64, actionUpdate *EditIncidentPostMortemToDoActionParams) error
	DeleteIncidentPostMortemToDoActionItem(ctx context.Context, incidentId uint64, postMortemId *uint64, id uint64) error
	SyncToDoActionStatusFromTCOCP(ctx context.Context, incidentId uint64, postMortemId *uint64) error
	CreatePostMortemToDoActionsFromFeishuDoc(ctx context.Context, incidentId uint64, feishuURL string) ([]*entity.IncidentPostMortemToDoAction, error)

	CreateFeishuTask(ctx context.Context, task *entity.FeishuTask) (string, error)
	UpdateFeishuTask(ctx context.Context, id string, task *entity.FeishuTask) error
	CompleteFeishuTask(ctx context.Context, id string) error
	DeleteFeishuTask(ctx context.Context, id string) error
}
