Adding a Camera Collision to an existing script

So I’m wondering how to add camera collision to the following script? The camera works fine it just goes through the walls.

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

public class ThirdPersonCamera : MonoBehaviour
{
    public bool lockCursor;
    public float mouseSensitivity = 1.5f;
    public Transform target;
    public float dstFromTarget = 3.5f;
    public Vector2 pitchMinMax = new Vector2(-20, 70);

    public float rotationSmoothTime = 0.12f;
    Vector3 rotationSmoothVelocity;
    Vector3 currentRotation;

    float yaw;
    float pitch;

    void Start()
    {
        if (lockCursor)
        {
            Cursor.lockState = CursorLockMode.Locked;
            Cursor.visible = false;
        }
    }

    void LateUpdate()
    {
        yaw += Input.GetAxis("Mouse X") * mouseSensitivity;
        pitch -= Input.GetAxis("Mouse Y") * mouseSensitivity;
        pitch = Mathf.Clamp(pitch, pitchMinMax.x, pitchMinMax.y);

        currentRotation = Vector3.SmoothDamp(currentRotation, new Vector3(pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime);
        transform.eulerAngles = currentRotation;

        transform.position = target.position - transform.forward * dstFromTarget;

        
    }
}

Most games deal with it by moving the camera closer to the player. So you could just raycast in the direction the camera is moving or depending on your setup, you may just be able to raycast behind the camera. From that raycast, you can ensure that the camera is always a min distance from a wall and anything below that distance is deducted from your target distance to the player.

Thank you, I will try this.