package uebung06;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class Field {
    private Sudoku sudoku;
    private int x;
    private int y;
    private VALUE value = null;

    private List<Field> dependents;
    private Set<VALUE> domain;
    

    public Field(Sudoku sudoku, int x, int y) {
        this.sudoku = sudoku;
        this.x = x;
        this.y = y;
    }

    public Sudoku getSudoku() {
        return sudoku;
    }

    public int getx() {
        return x;
    }

    public int gety() {
        return y;
    }

    public VALUE getValue() {
        return value;
    }

    public void setValue(VALUE value) {
        this.value = value;
    }

    public List<Field> getDependents() {
        if (dependents == null) {
            dependents = calculateDependents();
        }
        return dependents;
    }

    public Set<VALUE> getDomainSet() {
        return domain;
    }

    public boolean isEmpty() {
        return value == null;
    }

    @Override
    public String toString() {
        if (value != null) {
            return value.toString();
        } else {
            return ".";
        }
    }


    //TODO
    private List<Field> calculateDependents() {
        List<Field> rtn = new ArrayList<>();

        //add all the ones in the same col
        for (int i = 0; i < 9; i++) {
            rtn.add(sudoku.getField(x, i));
        }

        // //add all the ones in the same row
        for (int i = 0; i < 9; i++) {
            rtn.add(sudoku.getField(i, y));
        }




        return rtn;
    }
}
