package entity

import "dataservices/commons/utils"

// tablename
const (
	TableGhappEvent                  = "ghapp_event"
	TableGhappPreflightRequest       = "ghapp_preflight_request"
	TableGhappAuthorization          = "ghapp_authorization"
	TableGhappAuthorizedInstallation = "ghapp_authorized_installation"
)

// ghapp_authorization state enum
const (
	GhappAuthorizationStatePreflight   = "preflight"
	GhappAuthorizationStateUnconfirmed = "unconfirmed"
	GhappAuthorizationStateConfirmed   = "confirmed"
	GhappAuthorizationStateRevoked     = "revoked"
)

// ghapp_authorized_installation state enum
const (
	GhappAuthorizedInstallationStateInstalled   = "installed"
	GhappAuthorizedInstallationStateSuspended   = "suspended"
	GhappAuthorizedInstallationStateUninstalled = "uninstalled"
)

type GhappEvent struct {
	ID             uint64         `gorm:"column:id" json:"id"`
	GithubDelivery string         `gorm:"github_delevery" json:"github_delevery"`
	GithubEvent    string         `gorm:"github_event" json:"github_event"`
	Payload        string         `gorm:"payload" json:"payload"`
	CreatedAt      utils.JsonTime `gorm:"column:created_at" json:"created_at"`
	UpdatedAt      utils.JsonTime `gorm:"column:updated_at" json:"updated_at"`
}

type GhappPreflightRequest struct {
	ID        uint64         `gorm:"column:id" json:"id"`
	OrgId     uint64         `gorm:"column:org_id" json:"org_id"`
	ProjectId uint64         `gorm:"column:project_id" json:"project_id"`
	CreatedBy string         `gorm:"column:created_by" json:"created_by"`
	CreatedAt utils.JsonTime `gorm:"column:created_at" json:"created_at"`
	UpdatedAt utils.JsonTime `gorm:"column:updated_at" json:"updated_at"`
}

type GhappAuthorization struct {
	ID                    uint64         `gorm:"column:id" json:"id"`
	DataappId             uint64         `gorm:"dataapp_id" json:"dataapp_id"`
	PreflightRequestId    uint64         `gorm:"preflight_request_id" json:"preflight_request_id"`
	AuthorizeAccountId    int64          `gorm:"authorize_account_id" json:"authorize_account_id"`
	AuthorizeAccountLogin string         `gorm:"authorize_account_login" json:"authorize_account_login"`
	State                 string         `gorm:"state" json:"state"`
	CreatedAt             utils.JsonTime `gorm:"column:created_at" json:"created_at"`
	UpdatedAt             utils.JsonTime `gorm:"column:updated_at" json:"updated_at"`
}

type GhappAuthorizedInstallation struct {
	ID                   uint64         `gorm:"column:id" json:"id"`
	GhappAuthorizationId uint64         `gorm:"ghapp_authorization_id" json:"ghapp_authorization_id"`
	InstallationId       int64          `gorm:"installation_id" json:"installation_id"`
	State                string         `gorm:"state" json:"state"`
	CreatedAt            utils.JsonTime `gorm:"column:created_at" json:"created_at"`
	UpdatedAt            utils.JsonTime `gorm:"column:updated_at" json:"updated_at"`
}
