using System;
using Assets.Source.Misc;
using Assets.Source.Patterns;
using DG.Tweening;
using UnityEngine;

namespace Assets.Source.Core.Gameplay.Sidescroller
{
    public class CameraSidescroller : Singleton<CameraSidescroller>
    {
        public Camera Camera;
        public Transform Target;
        public float LerpSpeed = 5;

        private float _defaultHeight;

        protected override void Awake()
        {
            base.Awake();
            _defaultHeight = transform.position.z;
        }

        void FixedUpdate()
        {
            if (Target == null)
                return;
            var pos = Vector3.Lerp(transform.position, Target.position, Time.fixedDeltaTime * LerpSpeed);
            pos.z = _defaultHeight;
            transform.position = pos;
        }

        public void ShakePos(CamShakeArgs args)
        {
            Camera.DOShakePosition(args.Duration, args.Strength, args.Vibrato, args.Randomness);
        }
    }
}
