package org.academiadecodigo.enuminatti.paint.grid;

/**
 * MIT License
 * (c) 2017 Ricardo Constantino
 */

public class Cell {
    private boolean painted;
    private Swatch currentSwatch;
    private Position position;

    Cell(int col, int row) {
        painted = false;
        position = new Position(col, row);
        currentSwatch = Swatch.WHITE;
    }

    public boolean isPainted() {
        return currentSwatch != Swatch.WHITE && painted;
    }

    public Position getPosition() {
        return position;
    }

    void unpaint() {
        this.painted = false;
        currentSwatch = Swatch.WHITE;
    }

    void setPainted(char painted) {
        this.painted = painted != '0';
    }

    void setPainted(Swatch swatch) {
        currentSwatch = swatch == currentSwatch ? Swatch.WHITE : swatch;
        this.painted = swatch != Swatch.WHITE;
    }

    void togglePainted() {
        painted = !painted;
        currentSwatch = currentSwatch.getOpposite();
    }

    public char toChar() {
        return currentSwatch.toChar();
    }

    public Swatch getCurrentSwatch() {
        return currentSwatch;
    }
}
