package phase

import (
	"fmt"

	"github.com/tidbcloud/devops/entity"
	rmapi "github.com/tidbcloud/devops/pkg/service/remediationticket/api"
)

type PhaseCommercialOperation struct {
	*basePhase
}

func (p *PhaseCommercialOperation) PhaseName() string {
	return p.basePhase.phaseName
}

func (p *PhaseCommercialOperation) PhaseNo() uint {
	return p.basePhase.phaseNum
}

func (*PhaseCommercialOperation) Successors() []*Phase {
	return nil
}

func (*PhaseCommercialOperation) Predecessors() []*Phase {
	return nil
}

func (p *PhaseCommercialOperation) IsFinalized() bool {
	return p.basePhase.isFinalized
}

func (*PhaseCommercialOperation) AutoAdvance() bool {
	return true
}

func (p *PhaseCommercialOperation) Validate(context Context) error {
	return nil
}

func (p *PhaseCommercialOperation) ValidateAndUpdateTicket(origin *entity.RemediationTicket, patch rmapi.TransferTicketParam) error {
	return nil
}

func (p *PhaseCommercialOperation) Next(context Context) (Phase, error) {
	nextPhaseName, err := ResolveNextPhase(entity.RemediationTicketPhaseCommercialOperation, &context.TicketInstance)
	if err != nil {
		return nil, fmt.Errorf("resolve next phase failed for %s: %w", p.basePhase.phaseName, err)
	}
	nextPhase, err := GetPhaseByName(nextPhaseName)
	if err != nil {
		return nil, fmt.Errorf("get next phase failed for %s: %w", p.basePhase.phaseName, err)
	}
	return nextPhase, nil
}
