package model;

import java.awt.image.BufferedImage;

public class Entity {
	private String thisName;
	private Drawbox thisDrawbox;
	private Hitbox thisHitbox;
	private String type;
	private BufferedImage thisImage;
	private int width = 0;
	private int height = 0;
	
	public Entity(String name, String drawbox, String hitbox, BufferedImage sprite) {
		thisName = new String(name);
		thisDrawbox = new Drawbox(drawbox);
		setImage(sprite); // updates entity width and height, should be called before creating hitbox
		if(hitbox != null) {
			String[] dataHitbox = hitbox.split(" ");
			System.out.println("Создается обьект /"+name+"/. Shape Hitbox = /"+dataHitbox[0]+"/. Размер dataHitbox = /"+dataHitbox.length+"/.");
			if(dataHitbox[0].equals("Rectangle")) {
				thisHitbox = new HitboxRectangle(dataHitbox,this);
			}else if(dataHitbox[0].equals("Circle")) {
				thisHitbox = new HitboxCircle(dataHitbox,this);
			}
		}
	}
// при добавлении новой сущности по умолчанию создается у нее прямоугольный хитбокс
	public Entity(String name) {
		this.thisName = name;
		this.thisHitbox = new HitboxRectangle("Rectangle",this);
		this.thisDrawbox = new Drawbox();
	}
	
	public void setName(String outName) {
		thisName = outName;
	}
	
	public void setType(String type) {
		this.type = type;
	}
	
	public String getType() {
		return type;
	}
	
	public void setDrawbox(Drawbox outDrawbox) {
		thisDrawbox = outDrawbox;
	};
	
	public void setHitbox(Hitbox inputHitbox) {
		thisHitbox = inputHitbox;
	};
	
	public String getName() {
		return thisName;
	};
	
	public Drawbox getDrawbox() {
		return thisDrawbox;
	};
	
	public Hitbox getHitbox() {
		return thisHitbox;
	};
	
	/** @return BufferedImage object or null if an image is not set */
	public BufferedImage getImage() {
		return thisImage;
	}
	
	/** NOTE: Image setter updates entity width and height */
	public void setImage(BufferedImage sprite) {
		this.thisImage = sprite;
		if(sprite != null) {
			width = sprite.getHeight();
			height = sprite.getHeight();
		}
	}
	
	public void PrintEntity() {
		System.out.println("---------------------");
		System.out.println("Name: "+thisName);
		thisDrawbox.printToConsole();
		thisHitbox.printToConsole();
		System.out.println("---------------------");
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}
}
