package dto

import "time"

// ProviderAppConnectionResponse is the browser-facing provider app connection shape.
type ProviderAppConnectionResponse struct {
	ID                 string    `json:"id"`
	ExternalSubjectRef string    `json:"externalSubjectRef"`
	DisplayLabel       string    `json:"displayLabel"`
	RequiresUpgrade    bool      `json:"requiresUpgrade,omitempty"`
	MissingPermissions []string  `json:"missingPermissions,omitempty"`
	MissingEvents      []string  `json:"missingEvents,omitempty"`
	Enabled            bool      `json:"enabled"`
	CreatedAt          time.Time `json:"createdAt"`
	UpdatedAt          time.Time `json:"updatedAt"`
}

// ProviderAppInstallationResponse is the browser-facing provider app installation shape.
type ProviderAppInstallationResponse struct {
	ID          string                          `json:"id"`
	AppID       string                          `json:"appId"`
	AppSlug     string                          `json:"appSlug"`
	AppName     string                          `json:"appName"`
	AvatarURL   string                          `json:"avatarUrl"`
	MemberID    string                          `json:"memberId"`
	Handle      string                          `json:"handle"`
	Connections []ProviderAppConnectionResponse `json:"connections"`
	Enabled     bool                            `json:"enabled"`
	CreatedAt   time.Time                       `json:"createdAt"`
	UpdatedAt   time.Time                       `json:"updatedAt"`
}

// GiteaAppConfigResponse is the browser-facing Gitea app config shape.
type GiteaAppConfigResponse struct {
	Registered  bool   `json:"registered"`
	InstanceURL string `json:"instanceUrl,omitempty"`
	DisplayName string `json:"displayName,omitempty"`
}

// GitHubAppConfigResponse is the browser-facing GitHub app config shape.
type GitHubAppConfigResponse struct {
	Registered bool   `json:"registered"`
	AppID      int64  `json:"appId,omitempty"`
	AppName    string `json:"appName,omitempty"`
	AppSlug    string `json:"appSlug,omitempty"`
	HTMLURL    string `json:"htmlUrl,omitempty"`
	OwnerLogin string `json:"ownerLogin,omitempty"`
}

// GitHubInstallationResponse is the minimal browser projection of one
// provider-side GitHub App installation. Connection state remains owned by
// ProviderAppConnectionResponse and is not duplicated here.
type GitHubInstallationResponse struct {
	InstallationID string `json:"installationId"`
	AccountLogin   string `json:"accountLogin"`
	TargetType     string `json:"targetType"`
}

// GitHubSetupProposalResponse is the credential-free browser projection of a
// verified, owner-bound GitHub App setup draft. The endpoint determines
// whether the opaque id can be promoted by an ordinary member or completed by
// its administrator owner; provider credentials never cross this boundary.
type GitHubSetupProposalResponse struct {
	ID         string    `json:"id"`
	Ready      bool      `json:"ready"`
	AppID      string    `json:"appId"`
	AppSlug    string    `json:"appSlug"`
	AppName    string    `json:"appName"`
	OwnerLogin string    `json:"ownerLogin,omitempty"`
	ExpiresAt  time.Time `json:"expiresAt"`
}

// GitHubSetupProposalEnvelope keeps the absence of a current proposal
// explicit without turning an ordinary empty state into an HTTP error.
type GitHubSetupProposalEnvelope struct {
	Proposal *GitHubSetupProposalResponse `json:"proposal"`
}

// GitHubSetupDraftResponse is the no-store browser projection returned after
// a workspace administrator verifies an existing GitHub App for a fresh AgentTeam
// setup. The encrypted credentials remain server-side; installations are
// advisory candidates until one is explicitly selected and exactly reverified.
type GitHubSetupDraftResponse struct {
	Proposal      GitHubSetupProposalResponse  `json:"proposal"`
	Installations []GitHubInstallationResponse `json:"installations"`
	// DiscoveryFailed keeps a successfully persisted encrypted draft
	// retryable when GitHub's advisory list endpoint is temporarily unavailable.
	DiscoveryFailed bool `json:"discoveryFailed,omitempty"`
}

// GitHubRegistrationStartResponse returns the AgentTeam HTTPS start URL for the
// server-side GitHub App manifest flow. The high-entropy provider state stays
// in the signed start token and browser callback cookie.
type GitHubRegistrationStartResponse struct {
	StartURL  string    `json:"startUrl"`
	ExpiresAt time.Time `json:"expiresAt"`
}
