package com.minelittlepony.client.model;

import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.entity.model.BipedEntityModel;
import net.minecraft.client.render.entity.model.PlayerEntityModel;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.Arm;

import com.minelittlepony.client.pony.PonyData;
import com.minelittlepony.model.ModelAttributes;
import com.minelittlepony.pony.IPony;
import com.minelittlepony.pony.IPonyData;
import com.minelittlepony.pony.meta.Size;

/**
 * The raw pony model without any implementations.
 * Will act effectively the same as a normal player model without any hints
 * of being cute and adorable.
 *
 * Modders can extend this class to make their own pony models if they wish.
 */
public abstract class ClientPonyModel<T extends LivingEntity> extends PlayerEntityModel<T> implements IPonyModel<T> {

    /**
     * The model attributes.
     */
    protected ModelAttributes<T> attributes = new ModelAttributes<>();

    /**
     * Associated pony data.
     */
    protected IPonyData metadata = new PonyData();

    public ClientPonyModel(float float_1, boolean boolean_1) {
        super(float_1, boolean_1);
    }

    @Override
    public void updateLivingState(T entity, IPony pony) {
        isChild = entity.isBaby();
        isSneaking = entity.isInSneakingPose();
        attributes.updateLivingState(entity, pony);
    }

    // Broken bridge
    @Override
    public void setAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) {
        super.method_17087(entity, move, swing, ticks, headYaw, headPitch);
    }

    @Override
    public ModelAttributes<?> getAttributes() {
        return attributes;
    }

    @Override
    public IPonyData getMetadata() {
        return metadata;
    }

    @Override
    public Size getSize() {
        return isChild ? Size.FOAL : getMetadata().getSize();
    }

    @Override
    public void apply(IPonyData meta) {
        metadata = meta;
    }

    @Override
    public ModelPart getHead() {
        return head;
    }

    @Override
    public boolean isRiding() {
        return isRiding;
    }

    @Override
    public float getSwingAmount() {
        return handSwingProgress;
    }


    @Override
    public ModelPart getArm(Arm side) {
        return super.getArm(side);
    }

    public ArmPose getArmPoseForSide(Arm side) {
        return side == Arm.RIGHT ? rightArmPose : leftArmPose;
    }

    /**
     * Copies this model's attributes into the passed model.
     */
    @Override
    public void setAttributes(BipedEntityModel<T> model) {
        super.setAttributes(model);

        if (model instanceof ClientPonyModel) {
            ((ClientPonyModel<T>)model).attributes = attributes;
            ((ClientPonyModel<T>)model).metadata = metadata;
        }
    }
}
