#!/usr/bin/env python3.4

from model.energy import Energy
from model.matter import Matter
from model.position import Position


class Cell:
    def __init__(self, energy: Energy, matter: Matter, position: Position, max_age,
                 min_energy: Energy, max_energy: Energy, min_matter: Matter, max_matter: Matter,
                 life_function, absorb_energy_function, absorb_matter_function):
        self.energy = energy
        self.matter = matter
        self.position = position
        self.life_function = life_function
        self.absorb_energy_function = absorb_energy_function
        self.absorb_matter_function = absorb_matter_function
        self.min_energy = min_energy
        self.max_energy = max_energy
        self.min_matter = min_matter
        self.max_matter = max_matter
        self.max_age = max_age
        self.age = 0
        self.life = True

    def next_life_step(self):
        self.age += 1
        self.process_energy()
        self.process_matter()
        self.life_function()
        return self.life

    def process_energy(self):
        self.energy += self.absorb_energy_function()

    def process_matter(self):
        self.matter += self.absorb_matter_function()

    def is_too_old(self):
        return self.age > self.max_age

    def has_not_enough_energy(self): # @TODO has_enough_energy OR "return self.energy < self.min_energy>"
        return self.energy > self.min_energy

    def has_not_enough_matter(self): # @TODO has_enough_energy OR "return self.energy < self.min_energy>"
        return self.matter > self.min_matter
