I am trying to understand the classical linear model
$$ Y=X\beta +\varepsilon$$ where instead we have that $\epsilon_k\sim N(0,a_k\sigma^2)$ are independent where $a_k>0$ are given. I want to recover all the standard information we get from least squares (LS estimator, residual sum squares and of an unbiased estimator for $\sigma^2$ . Setting $A=Diag(a_1,...,a_n)$, I have derived the weighted least squares estimator to be $\hat{\beta}=(X^TA^{-1}X)^{-1}X^TA^{-1}Y$. I am trying to convert this back to an OLS equation in order to get the residual sum of squares and an unbiased estimator of $\sigma^2$. Naively setting $Z=X^TA^{-1}$ causes issues so this won't work.
Computing $\hat{\beta}$ is simple only because the $a_1,..a_n$ are known. Can we still compute it even if they were unknown? What if the $a_1,...a_n$ all depended on another parameter $\eta$, how would we be able to solve for the least squares estimator? For instance Newton-Raphson would no longer be applicable.