package native

import (
	"git.marketally.com/tutus-one/tutus-chain/pkg/core/dao"
	"git.marketally.com/tutus-one/tutus-chain/pkg/util"
)

// CRIT-002: Domain-specific committee roles for reduced single point of failure.
const (
	RoleCommitteeLegal      uint64 = 100
	RoleCommitteeHealth     uint64 = 101
	RoleCommitteeEducation  uint64 = 102
	RoleCommitteeEconomy    uint64 = 103
	RoleCommitteeIdentity   uint64 = 104
	RoleCommitteeGovernance uint64 = 105
)

// CommitteeDomain represents a domain for committee authority.
type CommitteeDomain uint8

const (
	DomainLegal CommitteeDomain = iota
	DomainHealth
	DomainEducation
	DomainEconomy
	DomainIdentity
	DomainGovernance
)

// DomainCommitteeRole maps domains to their committee role IDs.
var DomainCommitteeRole = map[CommitteeDomain]uint64{
	DomainLegal:      RoleCommitteeLegal,
	DomainHealth:     RoleCommitteeHealth,
	DomainEducation:  RoleCommitteeEducation,
	DomainEconomy:    RoleCommitteeEconomy,
	DomainIdentity:   RoleCommitteeIdentity,
	DomainGovernance: RoleCommitteeGovernance,
}

// HasDomainCommitteeAuthority checks if an address has committee authority for a specific domain.
func (r *RoleRegistry) HasDomainCommitteeAuthority(d *dao.Simple, address util.Uint160, domain CommitteeDomain, blockHeight uint32) bool {
	roleID, ok := DomainCommitteeRole[domain]
	if !ok {
		return false
	}
	return r.HasRoleInternal(d, address, roleID, blockHeight)
}
