package listing

import (
	"context"
)

func (s *Service) ListPendingReview(ctx context.Context) ([]ListingDTO, error) {
	if s.repo == nil {
		return nil, ErrDependencyUnavailable
	}
	return s.repo.ListPendingReview(ctx)
}

func (s *Service) ListAdmin(ctx context.Context, query AdminListQuery) (*AdminListResult, error) {
	if s.repo == nil {
		return nil, ErrDependencyUnavailable
	}
	return s.repo.ListAdmin(ctx, query)
}

func (s *Service) FindAdmin(ctx context.Context, id uint64) (*ListingDTO, error) {
	if s.repo == nil {
		return nil, ErrDependencyUnavailable
	}
	return s.repo.FindAdmin(ctx, id)
}

func (s *Service) AdminOffline(ctx context.Context, adminID uint64, id uint64, req AdminActionRequest, meta AuditMeta) (*ListingDTO, error) {
	if s.repo == nil {
		return nil, ErrDependencyUnavailable
	}
	if req.Reason == "" {
		return nil, ErrInvalidInput
	}
	return s.repo.AdminOffline(ctx, adminID, id, req, meta)
}

func (s *Service) AdminMarkAbnormal(ctx context.Context, adminID uint64, id uint64, req AdminActionRequest, meta AuditMeta) (*ListingDTO, error) {
	if s.repo == nil {
		return nil, ErrDependencyUnavailable
	}
	if req.Reason == "" {
		return nil, ErrInvalidInput
	}
	return s.repo.AdminMarkAbnormal(ctx, adminID, id, req, meta)
}

func (s *Service) Approve(ctx context.Context, id uint64) (*ListingDTO, error) {
	if s.repo == nil {
		return nil, ErrDependencyUnavailable
	}
	return s.repo.Approve(ctx, id)
}

func (s *Service) AdjustReviewPrice(ctx context.Context, adminID uint64, id uint64, req AdminPriceAdjustRequest, meta AuditMeta) (*ListingDTO, error) {
	if s.repo == nil {
		return nil, ErrDependencyUnavailable
	}
	if req.BuyerRatio <= 0 && req.BuyerTotalPriceCent <= 0 {
		return nil, ErrInvalidPrice
	}
	return s.repo.AdjustReviewPrice(ctx, adminID, id, req, meta)
}

func (s *Service) Reject(ctx context.Context, id uint64, req ReviewRequest) (*ListingDTO, error) {
	if s.repo == nil {
		return nil, ErrDependencyUnavailable
	}
	if req.Reason == "" {
		return nil, ErrInvalidInput
	}
	return s.repo.Reject(ctx, id, req)
}
