package models

import "time"

// BranchProtection defines push rules for a branch pattern.
type BranchProtection struct {
	ID             int64     `xorm:"'id' pk autoincr"`
	RepoID         int64     `xorm:"'repo_id' notnull index"`
	Pattern        string    `xorm:"'pattern' notnull"` // exact name or glob like "release/*"
	RequirePR      bool      `xorm:"'require_pr' default true"`
	BlockForcePush bool      `xorm:"'block_force_push' default true"`
	AllowedUsers   string    `xorm:"'allowed_users'"` // comma-sep; these users may push directly
	CreatedAt      time.Time `xorm:"'created_at' created"`
}

// BranchingModel stores the naming convention config for a repo (one row per repo).
type BranchingModel struct {
	ID             int64     `xorm:"'id' pk autoincr"`
	RepoID         int64     `xorm:"'repo_id' notnull unique"`
	Enabled        bool      `xorm:"'enabled' default false"`
	FeaturePrefix  string    `xorm:"'feature_prefix'"`
	BugfixPrefix   string    `xorm:"'bugfix_prefix'"`
	ReleasePrefix  string    `xorm:"'release_prefix'"`
	HotfixPrefix   string    `xorm:"'hotfix_prefix'"`
	UpdatedAt      time.Time `xorm:"'updated_at' updated"`
}

// MergeStrategies stores which PR merge strategies are allowed for a repo (one row per repo).
type MergeStrategies struct {
	ID               int64 `xorm:"'id' pk autoincr"`
	RepoID           int64 `xorm:"'repo_id' notnull unique"`
	AllowMergeCommit bool  `xorm:"'allow_merge_commit' default true"`
	AllowSquash      bool  `xorm:"'allow_squash' default true"`
	AllowRebase      bool  `xorm:"'allow_rebase' default true"`
}

// Webhook delivers event payloads to external URLs.
type Webhook struct {
	ID              int64      `xorm:"'id' pk autoincr"`
	RepoID          int64      `xorm:"'repo_id' notnull index"`
	Title           string     `xorm:"'title'"`
	URL             string     `xorm:"'url' notnull"`
	Secret          string     `xorm:"'secret'"`
	Events          string     `xorm:"'events' notnull"` // "push,pull_request,issue"
	Active          bool       `xorm:"'active' default true"`
	LastStatus      int        `xorm:"'last_status'"`
	LastDeliveredAt *time.Time `xorm:"'last_delivered_at'"`
	CreatedAt       time.Time  `xorm:"'created_at' created"`
}
