package sql

import (
	"context"
	"tercul/internal/domain"
	"tercul/internal/platform/config"

	"gorm.io/gorm"
)

type cityRepository struct {
	domain.BaseRepository[domain.City]
	db *gorm.DB
}

// NewCityRepository creates a new CityRepository.
func NewCityRepository(db *gorm.DB, cfg *config.Config) domain.CityRepository {
	return &cityRepository{
		BaseRepository: NewBaseRepositoryImpl[domain.City](db, cfg),
		db:             db,
	}
}

// ListByCountryID finds cities by country ID
func (r *cityRepository) ListByCountryID(ctx context.Context, countryID uint) ([]domain.City, error) {
	var cities []domain.City
	if err := r.db.WithContext(ctx).Where("country_id = ?", countryID).Find(&cities).Error; err != nil {
		return nil, err
	}
	return cities, nil
}
