package pp.monopoly.model.fields;

import pp.monopoly.game.server.Player;

/**
 * Represents an abstract property field in the Monopoly game.
 * Contains attributes related to ownership, price, rent, and mortgage status.
 */
public abstract class PropertyField extends Field {

    private final int price;
    protected final int rent;
    private Player owner;
    private boolean mortgaged = false;

    /**
     * Constructs a PropertyField with the specified name, ID, price, and rent.
     *
     * @param name  the name of the property
     * @param id    the unique identifier for the property
     * @param price the purchase price of the property
     * @param rent  the base rent for the property
     */
    protected PropertyField(String name, int id, int price, int rent) {
        super(name, id);
        this.price = price;
        this.rent = rent;
    }

    /**
     * Calculates the rent for this property.
     * The calculation may depend on various factors specific to property type.
     *
     * @return the calculated rent for this property
     */
    public abstract int calcRent();

    /**
     * Gets the purchase price of the property.
     *
     * @return the price of the property
     */
    public int getPrice() {
        return price;
    }

    /**
     * Gets the mortgage value (hypothecary value) of the property.
     * Typically, this is half of the property price.
     *
     * @return the mortgage value of the property
     */
    public int getHypo() {
        return price / 2;
    }

    /**
     * Gets the owner of the property.
     *
     * @return the Player who owns the property, or null if the property is unowned
     */
    public Player getOwner() {
        return owner;
    }

    /**
     * Sets the owner of the property.
     *
     * @param player the Player who will own this property
     */
    public void setOwner(Player player) {
        owner = player;
    }

    /**
     * Checks if the property is currently mortgaged.
     *
     * @return true if the property is mortgaged, false otherwise
     */
    public boolean isMortgaged() {
        return mortgaged;
    }

    /**
     * Sets the mortgage status of the property.
     *
     * @param mortgaged true to mark the property as mortgaged, false to unmark it
     */
    public void setMortgaged(boolean mortgaged) {
        this.mortgaged = mortgaged;
    }
}
