namespace CartWise.Domain.Entities;

public class StoreLocation
{
    public Guid StoreLocationId { get; private set; }

    public Guid RetailerId { get; private set; }

    public string? ExternalStoreId { get; private set; }

    public string Name { get; private set; } = null!;

    public string? AddressLine1 { get; private set; }

    public string? AddressLine2 { get; private set; }

    public string? City { get; private set; }

    public string? Region { get; private set; }

    public string? PostalCode { get; private set; }

    public string? CountryCode { get; private set; }

    public decimal? Latitude { get; private set; }

    public decimal? Longitude { get; private set; }

    public DateTime CreatedUtc { get; private set; }

    public DateTime UpdatedUtc { get; private set; }

    private StoreLocation()
    {
    }

    public StoreLocation(
        Guid retailerId,
        string name,
        DateTime createdUtc,
        string? externalStoreId = null,
        string? addressLine1 = null,
        string? addressLine2 = null,
        string? city = null,
        string? region = null,
        string? postalCode = null,
        string? countryCode = null,
        decimal? latitude = null,
        decimal? longitude = null)
    {
        if (retailerId == Guid.Empty)
        {
            throw new ArgumentException("RetailerId is required.", nameof(retailerId));
        }

        if (string.IsNullOrWhiteSpace(name))
        {
            throw new ArgumentException("Store name is required.", nameof(name));
        }

        StoreLocationId = Guid.NewGuid();
        RetailerId = retailerId;
        Name = name.Trim();
        ExternalStoreId = externalStoreId;
        AddressLine1 = addressLine1;
        AddressLine2 = addressLine2;
        City = city;
        Region = region;
        PostalCode = postalCode;
        CountryCode = countryCode;
        Latitude = latitude;
        Longitude = longitude;
        CreatedUtc = createdUtc;
        UpdatedUtc = createdUtc;
    }
}
