package vercel

import (
	"github.com/tidbcloud/pkgv2/bizerr"
	"github.com/tidbcloud/pkgv2/svcid"
)

type Conclusion string

const (
	ConclusionSucceeded Conclusion = "succeeded"
	ConclusionFailed    Conclusion = "failed"
)

var (
	ErrorCodeVercelApiUnrecoverableError = bizerr.NewInternalErrCode(svcid.EcosystemService, 1, "vercel api unrecoverable error")
	ErrorCodeVercelApiNotFoundError      = bizerr.NewInternalErrCode(svcid.EcosystemService, 2, "vercel api not found error")
)

type IntegrationAccessTokenVercelAPIResponse struct {
	TokenType      string  `json:"token_type"`
	AccessToken    string  `json:"access_token"`
	InstallationID string  `json:"installation_id"`
	UserID         string  `json:"user_id"`
	TeamID         *string `json:"team_id"`
}

type RetrieveProjectQueryParameters struct {
	ExcludeRepos      string `url:"excludeRepos,omitempty"`
	From              string `url:"from,omitempty"`
	Until             string `url:"until,omitempty"`
	GitForkProtection string `url:"gitForkProtection,omitempty"`
	Limit             string `url:"limit,omitempty"`
	Repo              string `url:"repo,omitempty"`
	Search            string `url:"search,omitempty"`
	TeamID            string `url:"teamId,omitempty"`
}

type TeamIDQueryParameter struct {
	TeamID string `url:"teamId,omitempty"`
}

type Project struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type Pagination struct {
	Count int64 `json:"count"`

	Next *int64 `json:"next"`
	Prev *int64 `json:"prev"`
}

type RetrieveProjectResponse struct {
	Projects   []Project  `json:"projects"`
	Pagination Pagination `json:"pagination"`
}

type RetrieveIntegrationConfigurationResponse struct {
	ID                string   `json:"id"`
	AllowedProjectIDs []string `json:"projects"` //When a configuration is limited to access certain projects, this will contain each of the project ID it is allowed to access. If it is not defined, the configuration has full access
}

type EnvironmentDescription struct {
	Key               string   `json:"key"`
	TargetEnvironment []string `json:"target"` // production, preview, development
	Type              string   `json:"type"`   // system, secret, encrypted, plain
	Value             string   `json:"value"`
	GitBranch         *string  `json:"gitBranch,omitempty"`
}

type EnvironmentInfo struct {
	ID  string `json:"id"`
	Key string `json:"key"`
}

type GetProjectResponse struct {
	ID             string `json:"id"`
	Name           string `json:"name"`
	FunctionRegion string `json:"serverlessFunctionRegion"`
}

type CreateCheckResponse struct {
	ID            string  `json:"id"`
	Name          string  `json:"name"`
	Path          *string `json:"path,omitempty"`
	Status        string  `json:"status"`
	Conclusion    *string `json:"conclusion,omitempty"`
	Blocking      bool    `json:"blocking"`
	DetailsURL    *string `json:"detailsUrl,omitempty"`
	IntegrationID string  `json:"integrationId"`
	DeploymentID  string  `json:"deploymentId"`
	ExternalID    *string `json:"externalId,omitempty"`
	CreatedAt     int64   `json:"createdAt"`
	UpdatedAt     int64   `json:"updatedAt"`
	StartedAt     *int64  `json:"startedAt,omitempty"`
	CompletedAt   *int64  `json:"completedAt,omitempty"`
	Rerequestable *bool   `json:"rerequestable,omitempty"`
}

type UpdateCheckBody struct {
	Conclusion Conclusion `json:"conclusion"`
	DetailsUrl string     `json:"detailsUrl"`
	Name       string     `json:"name"`
}

type GetDeploymentResponse struct {
	ID  string   `json:"id"`
	Env []string `json:"env"`
}
