// EN: Resource entity for bookable resources.
// VI: Entity Resource cho tài nguyên có thể đặt.

using BookingService.Domain.Exceptions;
using BookingService.Domain.SeedWork;

namespace BookingService.Domain.AggregatesModel.ResourceAggregate;

/// <summary>
/// EN: Resource entity - represents a bookable resource (room, bed, equipment).
/// VI: Entity Resource - đại diện cho tài nguyên có thể đặt (phòng, giường, thiết bị).
/// </summary>
public class Resource : Entity, IAggregateRoot
{
    private Guid _shopId;
    private string _name = null!;
    private string _resourceType = null!; // Room, Bed, Equipment
    private int _capacity;
    private bool _isActive;
    private DateTime _createdAt;

    public Guid ShopId => _shopId;
    public string Name => _name;
    public string ResourceType => _resourceType;
    public int Capacity => _capacity;
    public bool IsActive => _isActive;
    public DateTime CreatedAt => _createdAt;

    protected Resource()
    {
    }

    public Resource(Guid shopId, string name, string resourceType, int capacity = 1)
    {
        if (shopId == Guid.Empty)
            throw new DomainException("Shop ID cannot be empty");
        if (string.IsNullOrWhiteSpace(name))
            throw new DomainException("Resource name cannot be empty");
        if (string.IsNullOrWhiteSpace(resourceType))
            throw new DomainException("Resource type cannot be empty");

        Id = Guid.NewGuid();
        _shopId = shopId;
        _name = name.Trim();
        _resourceType = resourceType.Trim();
        _capacity = capacity;
        _isActive = true;
        _createdAt = DateTime.UtcNow;
    }

    public void Activate() => _isActive = true;
    public void Deactivate() => _isActive = false;

    /// <summary>
    /// EN: Update resource name.
    /// VI: Cập nhật tên tài nguyên.
    /// </summary>
    public void UpdateName(string name)
    {
        if (string.IsNullOrWhiteSpace(name))
            throw new DomainException("Resource name cannot be empty / Tên tài nguyên không được trống");

        _name = name.Trim();
    }

    /// <summary>
    /// EN: Update resource capacity.
    /// VI: Cập nhật sức chứa tài nguyên.
    /// </summary>
    public void UpdateCapacity(int capacity)
    {
        if (capacity < 0)
            throw new DomainException("Capacity cannot be negative / Sức chứa không được âm");

        _capacity = capacity;
    }
}
