package repository

import (
	dbgen "Yimaru-Backend/gen/db"
	"context"
)

type ReportedIssueRepository interface {
	CreateReportedIssue(ctx context.Context, arg dbgen.CreateReportedIssueParams) (dbgen.ReportedIssue, error)
	ListReportedIssues(ctx context.Context, limit, offset int32) ([]dbgen.ReportedIssue, error)
	ListReportedIssuesByUser(ctx context.Context, userID int64, limit, offset int32) ([]dbgen.ReportedIssue, error)
	CountReportedIssues(ctx context.Context) (int64, error)
	CountReportedIssuesByUser(ctx context.Context, userID int64) (int64, error)
	UpdateReportedIssueStatus(ctx context.Context, id int64, status string) error
	DeleteReportedIssue(ctx context.Context, id int64) error
	GetReportedIssueByID(ctx context.Context, id int64) (dbgen.ReportedIssue, error)
}

type ReportedIssueRepo struct {
	store *Store
}

func NewReportedIssueRepository(store *Store) ReportedIssueRepository {
	return &ReportedIssueRepo{store: store}
}

func (s *ReportedIssueRepo) CreateReportedIssue(ctx context.Context, arg dbgen.CreateReportedIssueParams) (dbgen.ReportedIssue, error) {
	return s.store.queries.CreateReportedIssue(ctx, arg)
}

func (s *ReportedIssueRepo) ListReportedIssues(ctx context.Context, limit, offset int32) ([]dbgen.ReportedIssue, error) {
	params := dbgen.ListReportedIssuesParams{
		Limit:  limit,
		Offset: offset,
	}
	return s.store.queries.ListReportedIssues(ctx, params)
}

func (s *ReportedIssueRepo) ListReportedIssuesByUser(ctx context.Context, userID int64, limit, offset int32) ([]dbgen.ReportedIssue, error) {
	params := dbgen.ListReportedIssuesByUserParams{
		UserID: userID,
		Limit:  limit,
		Offset: offset,
	}
	return s.store.queries.ListReportedIssuesByUser(ctx, params)
}

func (s *ReportedIssueRepo) CountReportedIssues(ctx context.Context) (int64, error) {
	return s.store.queries.CountReportedIssues(ctx)
}

func (s *ReportedIssueRepo) CountReportedIssuesByUser(ctx context.Context, userID int64) (int64, error) {
	return s.store.queries.CountReportedIssuesByUser(ctx, userID)
}

func (s *ReportedIssueRepo) UpdateReportedIssueStatus(ctx context.Context, id int64, status string) error {
	return s.store.queries.UpdateReportedIssueStatus(ctx, dbgen.UpdateReportedIssueStatusParams{
		ID:     id,
		Status: status,
	})
}

func (s *ReportedIssueRepo) DeleteReportedIssue(ctx context.Context, id int64) error {
	return s.store.queries.DeleteReportedIssue(ctx, id)
}

func (s *ReportedIssueRepo) GetReportedIssueByID(ctx context.Context, id int64) (dbgen.ReportedIssue, error) {
	return s.store.queries.GetReportedIssueByID(ctx, id)
}
