using System.Collections.Generic;
using System.Linq;
using UnityEngine;

[System.Serializable]
public class KeyframeDataCamera : KeyframeData
{
    public SerializableTransform CamTransform;

    public int CameraMode;
    public bool CameraLock;
    public float Fov            = 45;
    public float CamDist        = 5;
    public float CamHeight      = 1;
    public float TargetHeigh    = 1;
    public float CamAngle       = 0;
    public float MovSpeed       = 5;
    public float RotSpeed       = 1;
    public float ZoomSpeed      = 0.2f;

    public KeyframeDataCamera() { }

    public KeyframeDataCamera(CameraContainer camera)
    {
        Root = new SerializableTransform(camera.Camera.transform);
        CamTransform = new SerializableTransform(camera.Camera.Cam.transform);

        var settings = camera.Settings;
        CameraMode  = settings.CameraMode;
        CameraLock  = settings.CameraLock;
        Fov         = settings.Fov;
        CamDist     = settings.CamDist;
        CamHeight   = settings.CamHeight;
        TargetHeigh = settings.TargetHeight;
        CamAngle    = settings.CamAngle;
        MovSpeed    = settings.MovSpeed;
        RotSpeed    = settings.RotSpeed;
        ZoomSpeed   = settings.ZoomSpeed;
    }

    public override KeyframeData Clone()
    {
        var keyframe            = new KeyframeDataCamera();
        keyframe.Root           = new SerializableTransform(this.Root);
        keyframe.CamTransform   = new SerializableTransform(this.CamTransform);
        keyframe.CameraMode     = this.CameraMode;
        keyframe.CameraLock     = this.CameraLock;
        keyframe.Fov            = this.Fov;
        keyframe.CamDist        = this.CamDist;
        keyframe.CamHeight      = this.CamHeight;
        keyframe.TargetHeigh    = this.TargetHeigh;
        keyframe.CamAngle       = this.CamAngle;
        keyframe.MovSpeed       = this.MovSpeed;
        keyframe.RotSpeed       = this.RotSpeed;
        keyframe.ZoomSpeed      = this.ZoomSpeed;
        return keyframe;
    }

    public override KeyframeData Lerp(KeyframeData target1, float amount)
    {
        var target          = target1 as KeyframeDataCamera;
        var copy            = this.Clone() as KeyframeDataCamera;
        copy.Root           = copy.Root.LerpWith(target.Root, amount);
        copy.CamTransform   = copy.CamTransform.LerpWith(target.CamTransform, amount);
        copy.Fov            = Mathf.Lerp(copy.Fov, target.Fov, amount);
        copy.CamDist        = Mathf.Lerp(copy.CamDist, target.CamDist, amount);
        copy.CamHeight      = Mathf.Lerp(copy.CamHeight, target.CamHeight, amount);
        copy.TargetHeigh    = Mathf.Lerp(copy.TargetHeigh, target.TargetHeigh, amount);
        copy.CamAngle       = Mathf.Lerp(copy.CamAngle, target.CamAngle, amount);
        return copy;
    }
}